package com.pac.utils;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

/**
 * 网络判断的工具类
 * Created by 兴盛 on 2015/4/22.
 */
public class NetUtils {
    public static final String LOG_TAG = "ChiHuoBaoLogs";
    public static boolean isNetOk(Context context) {
        return getNetState(context).isAvailable();
    }

    public static boolean isWifi(Context context) {
        if (!isNetOk(context)) {
            return false;
        }
        if (getNetState(context).getType() == ConnectivityManager.TYPE_WIFI) {
            return true;
        }
        return false;
    }

    public static NetworkInfo getNetState(Context context) {
        ConnectivityManager mgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        return mgr.getActiveNetworkInfo();
    }
}
